package com.rocket.bedroom.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.rocket.bedroom.pojo.*;
import com.rocket.bedroom.service.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 周毅
 * @ClassName:
 * @Description: TODO
 * @Date: Create in 14:23 2020/5/13
 * @ModifyBy:
 */
@RestController
@ApiModel(value = "字典")
@RequestMapping(value = "/dictionary")
public class DictionaryController {

    @Resource
    private IGradeService gradeService;

    @Resource
    private IClassInfoService classInfoService;

    @Resource
    private IBlockService blockService;

    @Resource
    private IFloorService floorService;

    @Resource
    private IRoomService roomService;

    @Resource
    private IBerthService berthService;

    @ApiOperation(value = "获取所有年级列表")
    @GetMapping(value = "/getGradeAll")
    public List<GradeEntity> getGradeAll() {
        return gradeService.list();
    }

    @ApiOperation(value = "根据年级Id获取班级列表")
    @GetMapping(value = "/getClassInfoByGradeId/{gradeId}")
    public List<ClassInfoEntity> getClassInfoByGradeId(@PathVariable("gradeId") Long gradeId) {
        Assert.notNull(gradeId, "请选择年级");
        LambdaQueryWrapper<ClassInfoEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(ClassInfoEntity::getGradeId, gradeId);
        return classInfoService.list(lambdaQuery);
    }

    @ApiOperation(value = "获取所有楼栋信息")
    @GetMapping(value = "/getBlockAll")
    public List<BlockEntity> getBlockAll() {
        return blockService.list();
    }

    @ApiOperation(value = "根据选择楼栋ID获取楼层列表")
    @GetMapping(value = "/getFloorByBlockId/{blockId}")
    public List<FloorEntity> getFloorByBlockId(@PathVariable("blockId") Long blockId) {
        Assert.notNull(blockId, "请选择楼栋");
        LambdaQueryWrapper<FloorEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(FloorEntity::getBlockId, blockId);
        return floorService.list(lambdaQuery);
    }

    @ApiOperation(value = "根据选择楼层ID获取房间列表")
    @GetMapping(value = "/getRoomListByFloorId/{floorId}")
    public List<RoomEntity> getRoomListByFloorId(@PathVariable("floorId") Long floorId) {
        Assert.notNull(floorId, "请选择楼层");
        LambdaQueryWrapper<RoomEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(RoomEntity::getFloorId, floorId);
        return roomService.list(lambdaQuery);
    }

    @ApiOperation("根据房间Id获取床位列表")
    @GetMapping(value = "/getBerthByRoomId/{roomId}")
    public List<BerthEntity> getBerthByRoomId(@PathVariable("roomId") Long roomId) {
        Assert.notNull(roomId, "请选择楼层");
        LambdaQueryWrapper<BerthEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(BerthEntity::getRoomId, roomId).eq(BerthEntity::getBerthState, 0);
        return berthService.list(lambdaQuery);
    }


}
